package com.java.comprehensive.arithmetic.leecode.easy;

import util.ListNode;

/**
 * @Author: Dgg
 * @Date: 2022/1/6 21:35
 * 判断链表是否有环
 */
public class LeetCode_141 {

	public boolean hasCycle(ListNode head) {
		if (head == null || head.next == null) {
			return false;
		}
		ListNode low = head;
		ListNode pre = head.next;

		boolean flag = true;
		while (low != pre) {
			if (low == null || pre.next == null) {
				return false;
			}
			low = low.next;
			pre = pre.next.next;
		}
		return flag;
	}
}
